Skip to content

feat(aria-snapshot): add numberSubstitution option for baseline generation#40977

Closed
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-number-substitution
Closed

feat(aria-snapshot): add numberSubstitution option for baseline generation#40977
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:adityasingh2400/aria-snapshot-number-substitution

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Closes #40080.

The aria-snapshot baseline generator currently rewrites numbers and dates into \d+ regexes, which is helpful for live UIs but unwanted for tests against mocked endpoints where the values are stable. This adds a numberSubstitution: 'regex' | 'static' option (default 'regex' so existing baselines do not change) that can be set per matcher call or globally via the expect.toMatchAriaSnapshot config.

Usage:

// per call
await expect(page.locator('body')).toMatchAriaSnapshot(`...`, { numberSubstitution: 'static' });

// globally
export default defineConfig({
  expect: {
    toMatchAriaSnapshot: { numberSubstitution: 'static' },
  },
});

The option is plumbed through expressionArg on the existing to.match.aria channel, then read inside matchesExpectAriaTemplate to gate the regex-rewrite step in renderAriaTree's codegen mode.

Tests cover both modes plus the existing default behavior, including the precedence where a per-call option overrides the global config.

…ation

Closes microsoft#40080.

The aria-snapshot baseline generator currently rewrites numbers and dates
into \d+ regexes, which is helpful for live UIs but unwanted for tests
against mocked endpoints where the values are stable.

This adds a numberSubstitution: 'regex' | 'static' option (default 'regex'
so existing baselines do not change) that can be set per matcher or
globally via the expect config.
// To generate aria assertion with regex heuristics. The numberSubstitution
// option (default 'regex') lets callers opt out of auto-converting numbers
// and dates into \d+ regexes when the baseline values are stable.
const renderStringsAsRegex = options.numberSubstitution !== 'static';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns of regex substitution for all heuristics even if the user only asked about one heuristic.

@Skn0tt
Copy link
Copy Markdown
Member

Skn0tt commented May 26, 2026

This API shape isn't a good fit.

@Skn0tt Skn0tt closed this May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Be able to switch off regex number substitution for aria snapshots

2 participants